﻿$(document).ready(function () {
    $('a[href="#"]').click(function (event) {
        event.preventDefault();
    });

    InitBlockScreenOnAjax();
    InitAdditionalControls();
});

function InitBlockScreenOnAjax() {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);

    function InitializeRequest(sender, args) {
        BlockBody();
    }

    function EndRequest(sender, args) {
        UnblockBody();
    }
};

function InitAdditionalControls() {
    SetTimepicker();
    SetDatepicker();
    SetCollapsible();
    SetSpinner();
}

function SetTimepicker() {
    $(".timepicker").timepicker({
        controlType: 'select',
        timeOnlyTitle: 'Выберите время',
        timeText: 'Время',
        hourText: 'Часы',
        minuteText: 'Минуты',
        currentText: 'Текущее',
        closeText: 'ОК'
    });
};

function SetDatepicker() {
    $(".datepicker").datepicker({
        showOtherMonths: true,
        selectOtherMonths: true,
        dateFormat: "dd.mm.yy",
        showAnim: "fadeIn",
        changeMonth: true,
        changeYear: true,
        autosize: true,
        firstDay: 1,
    });
};

function SetCollapsible() {
    $(".collapsible").accordion({
        collapsible: true,
        animate: false,
        active: 0,
    });
};

function SetSpinner() {
    $(".spinner").spinner();
};

function CloseModal(id) {
    $("#" + id).dialog("close");
}

function ShowSysMsg(message, hide, hideAfter) {
    var elm = $("#SysMsg");
    elm.text(message);
    elm.show("blind", 1500);
    elm.effect("highlight", { color: "yellow" }, 2000).dequeue();

    if (hide) {
        setTimeout(function () {
            elm.text("");
            elm.hide();
        }, hideAfter);
    }
}

function ShowFormError(id, message) {
    $("#" + id).text(message);
    $("#" + id).show();
}

function BlockBody() {
    $("#BlockDiv").show();
}

function UnblockBody() {
    $("#BlockDiv").hide();
}
